﻿$(function() {
    ProdCreate.init();
    Utils.textBoxsOnEnter(ProdCreate.Create);
});


var ProdCreate =
{
    init: function() {
        $("#btnSave").click(this.Create);
        $("#prodid").focus();
        $(document).keyup(function(e) {
            if (e.keyCode == 27) {
                window.parent.utility.closePopUpUrl();
            }
        });
    },
    Create: function() {
        var prodid = $("#prodid");
        var prodName = $("#prodName");
        var unit = $("#unit");
        var unitvalue = $("#unitValue");
        var fee = $("#fee");

        targetFunction = (parent != undefined) ? parent.ErrorHelper : ErrorHelper;
        targetFunction.checkNonNull(prodid, m.Err0100);
        targetFunction.checkNonNull(prodName, m.Err0101);
        targetFunction.checkNonNull(unit, m.Err0102);
        targetFunction.checkNonNull(unitvalue, m.Err0103);
        targetFunction.checkNonNull(fee, m.Err0104);

        if (!targetFunction.popUpIfError()) {
            var param = $("#createProd").serialize();
            var cb = Utils.getCBfunction('Product');
            var ecb = function() { $("#prodid").focus(); };
            window.parent.utility.ajaxext("ProductService/Create", param, "POST", cb, ecb);
        }
    }
};
